
//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    formats: {},
    bottom: 0,
    readOnly: false,
    placeholder: '如何将内容回填到这里？...',
    _focus: false,
    detail:'<p>sss</p>'
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
  console.log("111111111111111111111")

  },
  onShow:function(){
    console.log("222222222222")
  },
  onReady:function(){
    console.log("3333333333")
  },
  onEditorReady(detail) {
    console.log("4444444444")
    var that = this
    wx.createSelectorQuery().select('#editor').context(function (res) {
      that.editorCtx = res.context
      if (!res) return
      that.editorCtx.setContents({
        // html: '<html><body><p>hello</p></body></html>',
        html: that.data.detail ? that.data.detail: '',
        success: function (res) {
          console.log("渲染成功")
        },
        fail: function (err) {
          console.log("渲染失败")
        }
      })
    }).exec()
  },

  format(e) {
    let { name, value } = e.target.dataset
    if (!name) return
    // console.log('format', name, value)
    this.editorCtx.format(name, value)

  },
  onStatusChange(e) {
    const formats = e.detail
    this.setData({ formats })
  },
  insertDivider() {
    this.editorCtx.insertDivider({
      success: function () {
        console.log('insert divider success')
      }
    })
  },
  // 获取内容
  clickLogText() {
    var that = this
    that.editorCtx.getContents({
      success: function (res) {
        console.log(res)
        that.setData({
          detail: res.html
        })
        console.log(that.data.detail)
        console.log(that.data.formats)
      }
    })
  },


})
